<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xlg="urn:xlg" xmlns:exsl="http://exslt.org/common">
	<xsl:output method="text" />
	<xsl:template match="/xlgDoc">
SET NOCOUNT ON
DECLARE @RC int
		<xsl:for-each select="Tables/Table">
		<xsl:sort select="@TableName"/>
		<xsl:variable name="TableName" select="@TableName" />
		<xsl:variable name="ClassName" select="@ClassName" /> 
   SELECT @RC=COUNT(*) FROM <xsl:value-of select="$TableName" />
       IF @RC <xsl:text disable-output-escaping="yes">&gt;</xsl:text> 0 
		BEGIN
			PRINT '**********************************************************************************************************'
			PRINT '<xsl:value-of select="$TableName" />	' + CAST(@RC As varchar)
			IF @RC <xsl:text disable-output-escaping="yes">&lt;</xsl:text> 20
			BEGIN
				SELECT * from <xsl:value-of select="$TableName" />
			END
			ELSE
			BEGIN
				SELECT TOP 20 * from <xsl:value-of select="$TableName" />
			END
		END
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>